package com.mstore.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 基类Action
 */
public class BaseAction extends ActionSupport {

	private static final long serialVersionUID = 2367639775586852631L;

	public static final String ERROR_TIP = "系统异常，请重新登陆！";

	/**
	 * map转json格式
	 */
	public String mapTojson(Map<String, Object> map) {
		return JSONObject.fromObject(map).toString();
	}

	/**
	 * list转json格式
	 */
	public String listTojson(Object list) {
		return JSONArray.fromObject(list).toString();
	}

	/**
	 * 获取当前时间
	 */
	public String getCreateTime() {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
				Locale.SIMPLIFIED_CHINESE);
		return sdf.format(date);
	}
	
	/**
	 * 获取当前时间
	 */
	public String getCreateTime(Long timeMillis) {
		Date date = new Date(timeMillis);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
				Locale.SIMPLIFIED_CHINESE);
		return sdf.format(date);
	}
}
